'''
@Version: 0.0.1
@Author: ider
@Date: 2020-02-04 15:48:09
@LastEditors: ider
@LastEditTime: 2020-03-23 22:19:13
@Description: 命令行编辑
'''

import click
import os
import logging
import logging.config

@click.group()
@click.option('--logging-config', default=os.path.join(os.path.dirname(__file__), "logging.conf"),
              help="logging config file for built-in python logging module", show_default=True)
def run(**kwargs):
    logging.config.fileConfig(kwargs['logging_config'])

@run.command()
@click.option('--year','-Y', default=None,type=int, help='select year or range year')
@click.option('--level','-L', default=2, type=int, help='wikipedia category level')
def miniworld(**kwargs):
    '''计算学科内的小世界性'''
    from miniworld import main
    main(kwargs['year'],kwargs['level'])

@run.command()
@click.option('--level','-L', default=2,type=int, help='wikipedia category level')
@click.option('--year','-Y', default=None,type=int, help='select year or range year')
@click.option('--interrupt','-I', default=False,type=bool, help='interrupt the process')
@click.option('--count','-C', default=None,type=int, help='学科最大点数限制')
def calGraph(**kwargs):
    '''使用缓存计算有向图结果'''
    from calcuatGraph import main
    main(level=kwargs['level'], desyear=kwargs['year'],interrupt=kwargs['interrupt'],count=kwargs['count'])

@run.command()
@click.option('--year','-Y', default=None,type=int, help='select year or range year')
def cacheGraph(**kwargs):
    '''有向图计算并缓存,只计算 lv2'''
    from directSubjectWorker import main
    main(desyear=kwargs['year'])

@run.command()
def pika(**kwargs):
    '''缓存队列存储到库'''
    from pika_receive import main
    main()


@run.command()
@click.option('--year','-Y', default=None,type=int, help='select year or range year')
@click.option('--mathod','-M', default=False,type=click.Choice(['google', 'category','random']))
def directrend(**kwargs):
    '''无向图趋势计算'''
    from undriect_rank import main
    main( desyear=kwargs['year'],method=kwargs['mathod'])

if __name__ == '__main__':
    run()